<?php
function show_sub_$global()
{
global $tbdirection;
global $tbstyborder;
global $tbstytype;
global $seprowcolor;
global $tbheadback;

$tbl="sub_$global";
$where=" catid='" . $_GET['catid'] . "'";
$edit="1";
$delet="1";


$tableheader="<tr bgcolor='". $tbheadback ."' style='background-image:url(images/tb-header-back.gif); background-repeat:repeat-x; background-position:bottom;' height='25'><td align='right' class='tbheadsty'>Name</td><td align='center' class='tbheadsty' width='5%'>Edit</td><td align='left' class='tbheadsty' width='5%'><input type='checkbox' name='Check_ctr' value='yes' onClick='Check(document.myform)'>
</td></tr>";
$nodata="Sorry But No Data Found";
$selected=array("id","title");
$rowsPerPage='10';
$pagNum='1';
$paget="&catid=" . $_GET['catid'] . "";
$linkcol="0";
$linkpage="0";
$colsnumber="3";
@pager($tbl,$where,$tableheader,$tablefooter,$paging,$nodata,$selected,$pagNum,$rowsPerPage,$edit,$delet,$linkcol,$linkpage,$paget,$colsnumber);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Add cat its mean adding new category //////////////////////////////////////////
function addcat_$global($globalpost)
{
date_default_timezone_set('Africa/Cairo');
$date = date("Y-m-d H:i:s");
/// check required inputs
if ($_POST['name'])
{
// filter inputs
$name=addslashes($_POST['name']);
$cshow=addslashes($_POST['cshow']);
$date_modified = "0000-00-00 00:00:00";
//add arrange to table
	$fields="*";
	$tbl=" cat_$global";
	$where = " id";
	$ordered=" id ";
	$arrange=" desc";
	$limit="100";
	$selectcat=selectdb($fields,$tbl,$where,$ordered, $arrange, $limit);
    $rd_num=mysql_num_rows($selectcat[0]);

    if ($rd_num == 0 )
   {
   $num=1 ;   
   } else if ( $rd_num > 0)
   {
   $num=$rd_num+1; 
   }

/////////
if ($_FILES['photo']['name'])
{
$photo=$photo;
$error="image Error";
$width = 50;
$height = 50;
// allowed File Types that will be upload
$allowedFileTypes = array("image/gif", "image/jpeg","image/pjpeg","image/bmp");
// upload image
$photo=upload_photo($photo,$allowedFileTypes,$error,$test,$width,$height);
}

// get fields
$fields = array("id","date","name","image","date_modified","cshow","ord");
// get values
$inserted = array("null","$date","$name","$photo","$date_modified","$cshow","$num");
// table name
$table = "cat_$global";

if ($_POST['doo']=='ed' and $_POST['ids'])
{
$tbl='cat_$global';
$dellimg = $_POST['dellimg'];
if ($photo)
{
$fields="*";
$where=' id=' .$_POST['ids'];
$ordered=' id';
$arrang='desc';
$limit=' 1';
$a=selectdb($fields,$tbl,$where,$ordered, $arrange, $limit);
$row=mysql_fetch_array($a[0]);
$ph="../" . $row['image'];
$th = substr($row['image'],10);
$th = "../uploads/th".$th;
@unlink($ph);
@unlink($th);
	$con=array(
		"name"=>"$name",
		"cshow"=>"$cshow",
		"image"=>"$photo",
		"date_modified"=>"$date"
	);
}
elseif(isset($dellimg))
{
$fields="*";
$where=' id=' .$_POST['ids'];
$ordered=' id';
$arrang='desc';
$limit=' 1';
$a=selectdb($fields,$tbl,$where,$ordered, $arrange, $limit);
$row=mysql_fetch_array($a[0]);
$ph="../" . $row['image'];
$th = substr($row['image'],10);
$th = "../uploads/th".$th;
@unlink($ph);
@unlink($th);
	$con=array(
		"name"=>"$name",
		"cshow"=>"$cshow",
		"image"=>"",
		"date_modified"=>"$date"
	);	
}
else
{
	$con=array(
		"name"=>"$name",
		"cshow"=>"$cshow",
		"date_modified"=>"$date"
	);
}
$wherer=" id=" . $_POST['ids'];
updatedb($tbl,$con,$wherer);
}
else
{
// insert into daba base
insert($fields,$inserted,$table);
}
}
else
{
// error message
echo "<script>alert('You Must Enter All Fields');</script>";
// back 
echo "<script>history.back(1);</script>";
}
}
// End Of function adding new category
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Add cat its mean adding new vidio category 

function addsub_$global($globalpost)
{
date_default_timezone_set('Africa/Cairo');
$date = date("Y-m-d H:i:s");
/// check required inputs
if ($_POST['title'])
{
// filter inputs
$title=addslashes($_POST['title']);
$content=addslashes($_POST['content']);

$date.=date("d") . " " . $mdate . " " . date("Y") . " " . date(" H:i:s");
$date_modified = "0000-00-00 00:00:00";
$cshow=$_POST['cshow'];
$catid=addslashes($_POST['catid']);
//$vembed=/*mysql_real_escape_string(*/$_POST['vembed']/*)*/;
//$vlink=/*mysql_real_escape_string(*/$_POST['vlink']/*)*/;

//add arrange to table
	$fields="*";
	$tbl=" sub_$global";
	$where = " catid='".$catid."'";
	$ordered=" id ";
	$arrange=" desc";
	$limit="100";
	$selectcat=selectdb($fields,$tbl,$where,$ordered, $arrange, $limit);
	$rd_num=mysql_num_rows($selectcat[0]);

    if ($rd_num == 0 )
   {
   $num=1 ;   
   }
   else if ( $rd_num > 0)
   {
   $num=$rd_num+1; 
   }

/////////

if ($_FILES['photo']['name'])
{
$photo=$photo;
$error="image Error";
$allowedFileTypes2 = array("image/png", "image/jpeg","image/pjpeg");
$photo=upload_photo($photo1,$allowedFileTypes2,$error);
}

if ($_FILES['attache']['name'])
{
$attache=$attache;
$error="image Error";
$allowedFileTypes3 = array("image/png", "image/jpeg","image/pjpeg");
$photo2=upload_photo($photo2,$allowedFileTypes3,$error);
}

// get fields
$fields = array(
				"id",
				"date",
				"title",
				"image",
				"attache",
				"content",
				"catid",
				"date_modified",
				"cshow",
				"ord"
		);

// get values
$inserted = array(
				"null",
				"$date",
				"$title",
				"$photo",
				"$attache",
				"$content",
				"$catid",
				"$date_modified",
				"$cshow",
				"$num"
		);
// table name
$table = "sub_$global";

if ($_POST['doo']=='ed' and $_POST['ids'])
{
$tbl='sub_$global';

if ($_FILES['photo']['name'] and $_FILES['attache']['name'])
{
$fields="*";
$where=' id=' .$_POST['ids'];
$ordered=' id';
$arrang='desc';
$limit=' 1';
$tbl='sub_$global';
$a=selectdb($fields,$tbl,$where,$ordered, $arrange, $limit);
$row=mysql_fetch_array($a[0]);
$b="../" . $row['image'];
$c="../" . $row['attache'];
echo $b;
echo $c;
@unlink($b);
@unlink($c);
$con=array(
			"title"=>"$title",
			"content"=>"$content",
			"catid"=>"$catid",
			"cshow"=>"$cshow",
			"date_modified"=>"$date",
			"image"=>"$photo",
			"attache"=>"$attache"
		);
}
elseif($_FILES['photo']['name'])
{
$row=mysql_fetch_array($a[0]);
$c="../" . $row['image'];
echo $c;
@unlink($c);
$con=array(
			"title"=>"$title",
			"content"=>"$content",
			"catid"=>"$catid",
			"cshow"=>"$cshow",
			"date_modified"=>"$date",
			"image"=>"$photo"
		);
}
elseif($_FILES['attache']['name'])
{
$fields="*";
$where=' id=' .$_POST['ids'];
$ordered=' id';
$arrang='desc';
$limit=' 1';
$tbl='sub_$global';
$a=selectdb($fields,$tbl,$where,$ordered, $arrange, $limit);
$row=mysql_fetch_array($a[0]);
$b="../" . $row['attache'];
echo $b;
@unlink($b);
$con=array(
			"title"=>"$title",
			"attache"=>"$attache",
			"content"=>"$content",
			"catid"=>"$catid",
			"cshow"=>"$cshow",
			"date_modified"=>"$date"
		);
}
else
{
$con=array(
			"title"=>"$title",
			"content"=>"$content",
			"catid"=>"$catid",
			"cshow"=>"$cshow",
			"date_modified"=>"$date"
		);	
}
$tbl='sub_$global';
$wherer=" id=" . $_POST['ids'];
updatedb($tbl,$con,$wherer);
}
else
{
// insert into data base
insert($fields,$inserted,$table);
}
}
else
{
// error message
echo "<script>alert('You Must Enter All Fields');</script>";
// back 
echo "<script>history.back(1);</script>";
}
}
// End Of function addvidio
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Show Categories
function show_cat_$global()
{
	global $tbdirection;
	global $tbstyborder;
	global $tbstytype;
	global $seprowcolor;
	global $tbheadback;

$tbl="cat_$global";
$where=' 1';
$edit="1";
$delet="1";
$tableheader="<tr bgcolor='". $tbheadback ."' style='background-image:url(images/tb-header-back.gif); background-repeat:repeat-x; background-position:bottom;' height='25'><td width='90%' align='center' class='tbheadsty'>Name</td><td align='center' class='tbheadsty' width='5%'>Edit</td>
<td align='left' class='tbheadsty' width='5%'><input type='checkbox' name='Check_ctr' value='yes' onClick='Check(document.myform)'></td></tr>";
$nodata="Sorry But No Data Found";
$selected=array("id","name");
$rowsPerPage='10';
$pagNum='1';
$linkcol="name";
$linkpage="vsub_$global";
$colsnumber="3";
@pager($tbl,$where,$tableheader,@$tablefooter,$paging,$nodata,$selected,$pagNum,$rowsPerPage,$edit,$delet,$linkcol,$linkpage,$paget,$colsnumber);
}
// End Of function showcat
?>